﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Metadata.Entity.ScheduleJob;
using T.FAS.Runtime.ScheduleJob.SPI;

namespace T.FAS.Runtime.ScheduleJob.Service
{
    public class ScheduleJobTriggerFactory
    {
        public ITrigger BuildTrigger(ScheduleJobExecContext context)
        {
            ITriggerBuilder builder = null;
            switch (context.ScheduleJobMetaData.ScheduleTrigger.TriggerType)
            {
                case Metadata.Entity.ScheduleJob.TriggerType.Schedule:
                    {
                        builder = new ScheduleTriggerBuilder();
                    }
                    break;
                case Metadata.Entity.ScheduleJob.TriggerType.Delay:
                    {
                        builder = new DelayTriggerBuilder();
                    }
                    break;
                case Metadata.Entity.ScheduleJob.TriggerType.ExactTime:
                    {
                        builder = new ExactTimeTriggerBuilder();
                    }
                    break;
                case Metadata.Entity.ScheduleJob.TriggerType.Immediate:
                    {
                        builder = new ImmediateTriggerBuilder();
                    }
                    break;
                default:
                    {
                        builder = new DefaultTriggerBuilder();
                    }
                    break;
            }
            return builder.Build(context);

        }
    }
}
